/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package socafeclient;

import entity.Insumos;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author wakowa
 */
public class TableModelInsumos extends AbstractTableModel {
    private ArrayList datalist = new ArrayList();
    private String[] columns = { "idInsumo", "Nombre", "TipoMedida", "CantidadEnStock" };
    
    
     @Override
    public int getRowCount() {
        return datalist.size();
    }

    @Override
    public int getColumnCount() {
        return columns.length;
    }
    
    @Override
    public Object getValueAt(int row, int col){
       Insumos i = (Insumos) datalist.get(row);
       switch (col) {
           case 0: //idInsumo
                return i.getIdinsumo();
            case 1: //Nombre
                return i.getNombre();
            case 2: //TipoMedida
                return i.getTipomedida();
            case 3: //CantidadEnStock
                return i.getCantidadstock();
            default:
                return false;
       }
    }
    public Insumos getInsumoAt(int row) {
        return (Insumos) datalist.get(row);
    }
    
    public Insumos removeInsumosAt(int row) {
        return (Insumos) datalist.remove(row);
    }

    public void addComanda(Insumos i) {
        datalist.add(i);
        fireTableDataChanged();
    }

    public void addInsumosList(List l) {
                
        Iterator iterador = l.listIterator();
        while(iterador.hasNext()){
            Insumos i = (Insumos) iterador.next();
            datalist.add(i);
        }
        
        fireTableDataChanged();
    }

    public TableModelInsumos(List l) {
        Iterator iterador = l.listIterator();
        while(iterador.hasNext()){
            Insumos i = (Insumos) iterador.next();
            datalist.add(i);
        }        
    }

    public TableModelInsumos() {
    }

    @Override
    public String getColumnName(int i) {
        return columns[i];
    }

    @Override
    public boolean isCellEditable(int row, int col) {
        switch (col) {
            case 0: //idInsumos
                return false;
            case 1: //Nombre
                return false;
            case 2: //TipoDeMedida
                return false;
            case 3: //CantidadStock
            return false;
            default:
                return false;
        }
    }    
    
    public void clear(List l)
    {
        datalist.clear();
        addInsumosList(l);        
    }
   
    
}
